
const { ccclass, property } = cc._decorator;

@ccclass
export default class Toast extends cc.Component {

    @property({ type: cc.Label })
    txt_label: cc.Label = null

    private _isEnd = false
    private _complateCallBack = null

    setParam(param: string) {
        this._isEnd = false
        this.txt_label.string = param
        let self = this
        this.node.position = new cc.Vec3(0, 0, 0)
        this.node.opacity = 255
        cc.tween(this.node)
            .to(0.1, { opacity: 255 })
            .delay(1)
            .to(0.5, { opacity: 0 })
            .call(() => {
                self.pushToCache()
            }).start()
    }

    setComplateCallBack(fun: Function) {
        this._complateCallBack = fun
    }

    move() {
        if (this._isEnd) return
        cc.tween(this.node).by(0.1, { y: 50 }).start()
    }

    pushToCache() {
        this._isEnd = true
        this.node.stopAllActions()
        if (this._complateCallBack) {
            this._complateCallBack(this)
        }
        this._complateCallBack = null
    }
}